/*
 * Copyright (C) 2010,2011  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#include "cqq.h"

void
cqq_init(cqq_ptr u)
{
    mpq_init(cqq_realref(u));
    mpq_init(cqq_imagref(u));
}

void
cqq_clear(cqq_ptr u)
{
    mpq_clear(cqq_realref(u));
    mpq_clear(cqq_imagref(u));
}

void
cqq_set(cqq_ptr u, cqq_ptr v)
{
    if (u != v) {
	mpq_set(cqq_realref(u), cqq_realref(v));
	mpq_set(cqq_imagref(u), cqq_imagref(v));
    }
}

void
cqq_neg(cqq_ptr u, cqq_ptr v)
{
    mpq_neg(cqq_realref(u), cqq_realref(v));
    mpq_neg(cqq_imagref(u), cqq_imagref(v));
}

void
eqq_add_qq_qq(cqq_ptr u, cqq_ptr v, cqq_ptr w)
{
    mpq_add(cqq_realref(u), cqq_realref(v), cqq_realref(w));
    mpq_add(cqq_imagref(u), cqq_imagref(v), cqq_imagref(w));
}

void
eqq_sub_qq_qq(cqq_ptr u, cqq_ptr v, cqq_ptr w)
{
    mpq_sub(cqq_realref(u), cqq_realref(v), cqq_realref(w));
    mpq_sub(cqq_imagref(u), cqq_imagref(v), cqq_imagref(w));
}

void
cqq_mul_2exp(cqq_ptr u, cqq_ptr v, int w)
{
    mpq_mul_2exp(cqq_realref(u), cqq_realref(v), w);
    mpq_mul_2exp(cqq_imagref(u), cqq_imagref(v), w);
}

void
cqq_div_2exp(cqq_ptr u, cqq_ptr v, int w)
{
    mpq_div_2exp(cqq_realref(u), cqq_realref(v), w);
    mpq_div_2exp(cqq_imagref(u), cqq_imagref(v), w);
}
